package Test3;

import java.util.HashSet;
import java.util.Scanner;

public class BabySittingProblem {
	public static void main(String[] args){
        System.out.println("Enter start time (hh:mm)= ");
        Scanner scanIn1 = new Scanner(System.in);
        String startTime = scanIn1.nextLine();
        
        System.out.println("Enter end time (hh:mm)= ");
        Scanner scanIn2 = new Scanner(System.in);
        String endTime = scanIn2.nextLine();
        
        //
		int jedaStartTime = startTime.indexOf(":");		
		String jamStartTime = startTime.substring(0, jedaStartTime);
		int intJamStartTime = Integer.parseInt(jamStartTime);
		String menitStartTime = startTime.substring(jedaStartTime+1);
		int intMenitStartTime = Integer.parseInt(menitStartTime);
				
		int jedaEndTime = endTime.indexOf(":");
		String jamEndTime = endTime.substring(0, jedaEndTime);
		int intJamEndTime = Integer.parseInt(jamEndTime);
		String menitEndTime = endTime.substring(jedaEndTime+1);
		int intMenitEndTime = Integer.parseInt(menitEndTime);
		
		double differenceMenit, differenceJam ;
		
		differenceJam = intJamEndTime - intJamStartTime;
		differenceMenit = intMenitEndTime - intMenitStartTime;
		
		if(differenceMenit < 0) {differenceJam--; differenceMenit = 60 + differenceMenit;}  
		if(differenceJam < 0) {differenceJam = 24 + differenceJam;}
		
        
        //
		HashSet<Integer> jam1 = new HashSet<Integer>(); //MENGGUNAKAN SET
		HashSet<Integer> jam2 = new HashSet<Integer>(); //MENGGUNAKAN SET
		HashSet<Integer> jam3 = new HashSet<Integer>(); //MENGGUNAKAN SET
		
		jam1.add(6);
		jam1.add(7);
		jam1.add(8);
		jam1.add(9);
		
		jam2.add(10);
		jam2.add(11);
		jam2.add(12);
		
		jam3.add(12);
		jam3.add(0);
		jam3.add(1);
		jam3.add(2);
		jam3.add(3);
		jam3.add(4);
		jam3.add(5);
		jam3.add(6);
		
		int n1=0;
		int sisaJam1=0;
		int totJam1=0;
		int n2=0;
		int sisaJam2=0;
		int totJam2=0;
		int n3=0;
		int sisaJam3=0;
		double sisaMenit=0;
		int totJam3=0;
		int totMenit=0;
		final double charge1=1.50;
		final double charge2=1.0;
		final double charge3=1.25;
		double totCharge=0;
		
		//if (intJamStartTime>=12) intJamStartTime=0;
		
		for (int i=0; i<3; i++){
			if ((intJamStartTime<9)&(intJamStartTime>6)){
				n1 = 9 - intJamStartTime; 
				sisaJam1 = intJamStartTime + n1;
				totJam1=totJam1+n1;
				intJamStartTime=sisaJam1;
			}else if ((intJamStartTime<12)&(intJamStartTime>6)){
				n2 = 12 - intJamStartTime; 
				sisaJam2 = n2;
				totJam2=totJam2+n2;
				intJamStartTime=n2;
			}else if(intJamStartTime<6){
				n3 = intJamStartTime - 0;
				sisaJam3 = 0; 
				sisaMenit =differenceMenit/60;
				totJam3=totJam3+n3;
				intJamStartTime=n3;
			}else if (intJamStartTime>=12){
				n3 = intJamStartTime-intJamEndTime; 
				sisaJam3 = 0;
				totJam3=n3;
				sisaMenit =differenceMenit/60;
			}else if (intJamStartTime>=6){
				n1 = 9 - intJamStartTime; 
				sisaJam1 = intJamStartTime + n1;
				totJam1=totJam1+n1;
				intJamStartTime=sisaJam1;
			}
		}
		totCharge = totJam1*charge1+totJam2*charge2+totJam3*charge3+sisaMenit*charge3;
		System.out.println("Total Fee = " + totJam1 + "*" + charge1 + "+" + totJam2 + "*" + charge2 + "+" + (totJam3+sisaMenit) + "*" + charge3 + "= " +totCharge);
		if(differenceJam == 0) System.out.println("Time Difference: " + differenceMenit + " minutes");
		else System.out.println("Time Difference: " + differenceJam + " hour "+ differenceMenit + " minutes");

	}
}
